<link type="text/css" rel="stylesheet" href="<?php echo $this->basePath('public/css/dbblack/css/ucenter.css'); ?>" />
<link type="text/css" rel="stylesheet" href="<?php echo $this->basePath('public/css/dbblack/css/product.css'); ?>" />

<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/artdialog/artDialog.js?skin=simple'); ?>"></script>
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/artdialog/plugins/iframeTools.js'); ?>"></script>
<script type='text/javascript' src="<?php echo $this->basePath('public/css/dbblack/js/jquery.form.js'); ?>"></script>

<div class="container clearfix">
    <?php echo $this->partial('shopfront/home/left_menu.phtml'); ?>
    <div class="uc-content">
        <h1 class="title"><span><?php echo $this->translate('我的订单'); ?>：</span></h1>
        <form class="form-search" style="margin: 0;" method="get">
            <div class="mt20 tr">
                <input type="text" style="height: 20px;width: 300px;" name="search_order_sn" value="<?php echo isset($_GET['search_order_sn']) ? $this->escapehtml($_GET['search_order_sn']) : ''; ?>" placeholder="<?php echo $this->translate('输入订单号'); ?>">&nbsp;
                <button type="submit" class="btn btn-main btn-mini"><?php echo $this->translate('搜索'); ?></button>
            </div>
        </form>
        <?php if($this->frontwebsite()->getIphoneSmsConfig('shop_phone_sms', 'phone_sms_type') and $user_info['user_phone'] == '') { ?>
        <p style="color: red;"><?php echo $this->translate('设置手机号码，可以接收到订单处理的短信通知。'); ?><a href="<?php echo $this->url('fronthome/default', array('action'=>'useredit')); ?>"><b><?php echo $this->translate('点击去设置手机号码'); ?></b></a></p>
        <?php } ?>

        <div class="order-menu">
            <ul class="tab-head">
                <li <?php if ($this->order_state == 10) echo 'class="current"'; ?>><a href="<?php echo $this->url('frontorder/default'); ?>"><?php echo $this->translate('有效订单'); ?><?php if ($this->order_state_num[10]>0) { ?>(<font color="red"><?php echo $this->order_state_num[10]; ?></font>)<?php } ?></a></li>
                <li <?php if ($this->order_state == 15) echo 'class="current"'; ?>><a href="<?php echo $this->url('frontorder/default/order_state', array('action'=>'index', 'order_state'=>15)); ?>"><?php echo $this->translate('付款中'); ?><?php if ($this->order_state_num[15]>0) { ?>(<font color="red"><?php echo $this->order_state_num[15]; ?></font>)<?php } ?></a></li>
                <li <?php if ($this->order_state == 20) echo 'class="current"'; ?>><a href="<?php echo $this->url('frontorder/default/order_state', array('action'=>'index', 'order_state'=>20)); ?>"><?php echo $this->translate('已付款'); ?><?php if ($this->order_state_num[20]>0) { ?>(<font color="red"><?php echo $this->order_state_num[20]; ?></font>)<?php } ?></a></li>
                <li <?php if ($this->order_state == 30) echo 'class="current"'; ?>><a href="<?php echo $this->url('frontorder/default/order_state', array('action'=>'index', 'order_state'=>30)); ?>"><?php echo $this->translate('未发货'); ?><?php if ($this->order_state_num[30]>0) { ?>(<font color="red"><?php echo $this->order_state_num[30]; ?></font>)<?php } ?></a></li>
                <li <?php if ($this->order_state == 40) echo 'class="current"'; ?>><a href="<?php echo $this->url('frontorder/default/order_state', array('action'=>'index', 'order_state'=>40)); ?>"><?php echo $this->translate('已发货'); ?><?php if ($this->order_state_num[40]>0) { ?>(<font color="red"><?php echo $this->order_state_num[40]; ?></font>)<?php } ?></a></li>
                <li <?php if ($this->order_state == 60) echo 'class="current"'; ?>><a href="<?php echo $this->url('frontorder/default/order_state', array('action'=>'index', 'order_state'=>60)); ?>"><?php echo $this->translate('交易完成'); ?><?php if ($this->order_state_num[60]>0) { ?>(<font color="red"><?php echo $this->order_state_num[60]; ?></font>)<?php } ?></a></li>
                <li <?php if ($this->order_state == -40) echo 'class="current"'; ?>><a href="<?php echo $this->url('frontorder/default/order_state', array('action'=>'index', 'order_state'=>-40)); ?>"><?php echo $this->translate('退货订单'); ?><?php if ($this->order_state_num[-40]>0) { ?>(<font color="red"><?php echo $this->order_state_num[-40]; ?></font>)<?php } ?></a></li>
                <li <?php if ($this->order_state == 0) echo 'class="current"'; ?>><a href="<?php echo $this->url('frontorder/default/order_state', array('action'=>'index', 'order_state'=>0)); ?>"><?php echo $this->translate('无效订单'); ?><?php if ($this->order_state_num[0]>0) { ?>(<font color="red"><?php echo $this->order_state_num[0]; ?></font>)<?php } ?></a></li>
            </ul>
        </div>
        <?php if ($this->order_list->getTotalItemCount() > 0) { ?>
        <table class="simple">
            <tr>
                <th><?php echo $this->translate('订单编号'); ?></th>
                <th width="100"><?php echo $this->translate('商品'); ?></th>
                <th width="100"><?php echo $this->translate('单价×件数'); ?></th>
                <th width="100"><?php echo $this->translate('商品操作'); ?></th>
                <th width="100"><?php echo $this->translate('订单金额'); ?></th>
                <th width="120"><?php echo $this->translate('下单时间'); ?></th>
                <th width="80"><?php echo $this->translate('订单状态'); ?></th>
                <th width="100"><?php echo $this->translate('操作'); ?></th>
            </tr>
            <?php foreach ($this->order_list as $order_key => $order_value) {
            $i = 1;
            $goodsArray = unserialize($order_value['goods_serialize']);
            $rowspan    = count($goodsArray);

            if(is_array($goodsArray) and !empty($goodsArray)) foreach($goodsArray as $goods_key => $goods_value) {
            ?>
            <tr  class="<?php if ($order_key%2==1) echo 'even'; else echo 'odd'; ?>">
                <?php if ($i == 1) { ?>
                <td rowspan="<?php echo $rowspan; ?>"><a href="<?php echo $this->url('frontorder/default/order_id', array('action'=>'showorder', 'order_id'=>$order_value['order_id'], 'order_state'=>$this->order_state, 'page'=>$this->page)); ?>"><?php echo $order_value['order_sn']; ?></a></td>
                <?php } ?>
                <td><a href="<?php echo $this->url('frontgoods/default', array('goods_id'=>$goods_value['goods_id'], 'class_id'=>$goods_value['class_id'])); ?>"><img title="<?php echo strip_tags($goods_value['goods_extend_info']); ?>" src="<?php echo $this->basePath($this->frontwebsite()->shopGoodsImage($goods_value['goods_image'])); ?>"  style=" width:80px;border:1px solid #D7D7D7"></a></td>
                <td><?php echo $order_value['currency_symbol'] . $goods_value['goods_shop_price'] . $order_value['currency_unit']; ?>×<?php echo $goods_value['buy_num']; ?></td>
                <td>
                    <p><button class="btn btn-small btn-success" onclick="again_buy('<?php echo $goods_value['goods_name']; ?>',<?php echo $goods_value['goods_id']; ?>,'<?php echo (isset($goods_value['goods_color']) ? $goods_value['goods_color'] : ''); ?>','<?php echo (isset($goods_value['goods_size']) ? $goods_value['goods_size'] :''); ?>', '<?php echo $this->basePath($this->frontwebsite()->shopGoodsImage($goods_value['goods_image'])); ?>',<?php echo $goods_value['class_id']; ?>);"><i class="icon-shopping-cart icon-white"></i> <?php echo $this->translate('再次购买'); ?></button></p>
                    <?php if ($order_value['order_state'] == 60  and !empty($order_value['pay_time']) and $this->order_state != -40) { ?>
                        <p style="margin-top: 5px;"><a href="<?php echo $this->url('frontorder/default/order_goods_id', array('action'=>'goodscomment', 'order_goods_id'=>$goods_key, 'order_state'=>$this->order_state, 'page'=>$this->page)); ?>" class="btn btn-small <?php if(isset($goods_value['comment_state'])) echo 'btn-primary'; else echo 'btn-danger'; ?>">
                                <?php if(isset($goods_value['comment_state'])) { ?>
                                    <?php echo $this->translate('已经评价'); ?>
                                <?php } else { ?>
                                    <?php echo $this->translate('尚未评价'); ?>
                                <?php } ?>
                            </a></p>
                    <?php } ?>
                </td>
                <?php if ($i == 1) { ?>
                <td rowspan="<?php echo $rowspan; ?>"><?php echo $order_value['currency_symbol'] . $order_value['order_amount'] . $order_value['currency_unit']; ?></td>
                <td rowspan="<?php echo $rowspan; ?>"><?php echo date("Y-m-d H:i:s",$order_value['order_time']); ?></td>
                <td rowspan="<?php echo $rowspan; ?>">
                    <?php echo $this->frontwebsite()->getOneOrderStateInfo($order_value['order_state']); ?>
                </td>
                <td rowspan="<?php echo $rowspan; ?>">
                    <p><a href="<?php echo $this->url('frontorder/default/order_id', array('action'=>'showorder', 'order_id'=>$order_value['order_id'], 'order_state'=>$this->order_state, 'page'=>$this->page)); ?>"><?php echo $this->translate('查看订单'); ?></a></p>
                    <?php if ($order_value['order_state'] == 10 or ($order_value['order_state'] == 30 and $order_value['pay_code'] == 'hdfk')) { ?>
                        <?php if ($order_value['order_state'] == 10) { ?>
                            <p style="margin-top: 3px;"><button class="btn btn-primary" onclick="order_pay('<?php echo $this->url('frontorder/default/order_id', array('action'=>'orderpay', 'order_id'=>$order_value['order_id'])); ?>', <?php echo $order_value['order_id']; ?>);"><?php echo $this->translate('立即付款'); ?></button></p>
                        <?php } ?>
                        <p style="margin-top: 3px;"><button class="btn btn-danger" onclick="if(window.confirm('<?php echo $this->translate('您确实要取消该订单吗？'); ?>')) {location.href='<?php echo $this->url('frontorder/default/order_id', array('action'=>'changestate', 'order_id'=>$order_value['order_id'], 'order_state'=>0, 'page'=>$this->page)); ?>'};"><?php echo $this->translate('取消订单'); ?></button></p>
                    <?php } else if ($order_value['order_state'] == 0) { ?>
                        <p style="margin-top: 3px;"><button class="btn btn-danger" onclick="if(window.confirm('<?php echo $this->translate('您确实要删除该订单吗？'); ?>')) {location.href='<?php echo $this->url('frontorder/default/order_id', array('action'=>'delOrder', 'order_id'=>$order_value['order_id'], 'order_state'=>0, 'page'=>$this->page)); ?>'};"><?php echo $this->translate('删除订单'); ?></button></p>
                    <?php } else if ($order_value['order_state'] == 40 and $this->order_state != -40) {
                        ?>
                        <?php if(($order_value['pay_code'] == 'alipay' or $order_value['pay_code'] == 'malipay') and $order_value['ot_order_state'] == 25) { ?>
                            <p style="margin-top: 3px;"><a href="https://www.alipay.com/" class="btn btn-primary" target="_blank"><?php echo $this->translate('确认收货'); ?></a></p>
                        <?php } else { ?>
                            <p style="margin-top: 3px;"><button class="btn btn-primary" onclick="location.href='<?php echo $this->url('frontorder/default/order_id', array('action'=>'orderReceipt', 'order_id'=>$order_value['order_id'], 'order_state'=>$this->order_state, 'page'=>$this->page)); ?>'"><?php echo $this->translate('确认收货'); ?></button></p>
                        <?php } ?>
                    <?php } ?>
                </td>
                <?php } ?>
            </tr>
           <?php $i++; } } ?>
        </table>
        <div class="page-nav"><?php echo ( count($this->order_list) > 0 ) ? $this->paginationControl($this->order_list, 'Sliding', 'site/dbpage',array('page_url'=>$this->url('frontorder/default/order_page', array('action'=>'index', 'order_state'=>$this->order_state)))) : ""; ?></div>

        <?php } else { echo '<p>' . $this->translate('暂时无订单！') . '</p>'; } ?>
    </div>
</div>

<table class="form" id="dbshop_goods_buy" style="display: none;" novalidate="true">
    <tbody>
    <tr>
        <td class="label"><?php echo $this->translate('商品信息'); ?>：</td><td id="dbshop_goods_buy_info"></td>
    </tr>
    <tr>
        <td class="label"><?php echo $this->translate('购买状态'); ?>：</td><td id="dbshop_goods_buy_state"></td>
    </tr>
    </tbody>
</table>

<form method="post" class="simple" id="pay_form" name="pay_form" style="display: none;" novalidate="true">
    <input type="hidden" name="payment_pee" id="payment_pee" value="">
    <table class="form">
        <tbody>
        <tr>
            <td class="label"><?php echo $this->translate('订单号'); ?></td>
            <td id="order-sn" style="width: 80%;"></td>
        </tr>
        <tr>
            <td class="label"><?php echo $this->translate('订单金额'); ?></td>
            <td id="order-amount" style="width: 80%;"></td>
        </tr>
        </tbody>
    </table>
    <table class="form">
        <tbody id="pay-list-show">
        </tbody>
    </table>
    <table class="form">
        <tbody>
        <tr>
            <td class="label"></td>
            <td class="tc" style="width: 80%;">
                <button type="submit" class="btn btn-primary"><?php echo $this->translate('点击支付'); ?></button>
            </td>
        </tr>
        </tbody>
    </table>
</form>

<form action="" method="post" id="to_cart" name="to_cart">
    <input type="hidden" name="buy_goods_num" id="buy_goods_num" value="1" />
    <input type="hidden" name="goods_id" id="goods_id" value="" />
    <input type="hidden" name="class_id" id="class_id" value="" />
    <input type="hidden" name="select_color_value" id="select_color_value" value="" />
    <input type="hidden" name="select_size_value" id="select_size_value" value="" />
</form>
<script>
    function again_buy(goods_name,goods_id,goods_color,goods_size,goods_image,class_id) {
        $('#goods_id').val(goods_id);
        $('#select_color_value').val(goods_color);
        $('#select_size_value').val(goods_size);
        $('#class_id').val(class_id);

        $.post("<?php echo $this->url('frontcart/default', array('action'=>'addCart')); ?>",$('#to_cart').formSerialize(),
            function(data){
                $('#dbshop_goods_buy_info').html('<img border="0" src="'+goods_image+'" style=" width:120px;border:1px solid #D7D7D7">&nbsp;&nbsp;'+goods_name);
                if(data == 'true') {
                    $('#dbshop_goods_buy_state').html('<b><?php echo $this->translate('添加购物车成功'); ?></b>&nbsp;&nbsp;<a href="<?php echo $this->url('frontcart/default'); ?>" class="btn btn-primary"><?php echo $this->translate('去购物车结算'); ?></a>');
                } else {
                    $('#dbshop_goods_buy_state').html('<b><?php echo $this->translate('添加购物车失败'); ?></b>&nbsp;&nbsp;'+data);
                }
                dlg = dialog({id:'dbshop_goods_buy',opacity:0.3,padding:'20px 10px 10px 20px',width:900,title:'<?php echo $this->translate('收货地址'); ?>',content:document.getElementById('dbshop_goods_buy'),lock:true});
                dlg.showModal();
            });
    }
    /**
     * 点击支付的操作
     * @param pay_url
     * @param order_id
     */
    function order_pay(pay_url, order_id) {
        $("#pay_form").attr('action',pay_url);
        $('#pay-list-show').html('');

        $.post('<?php echo $this->url('frontorder/default/order_id', array('action'=>'getOrderPay')); ?>', {'order_id':order_id}, function(data){
                if (data)
                {
                    if(data.state != 'true') {
                        alert(data.message);
                        return;
                    }

                    $('#order-amount').html(data['order']['order_amount']);
                    $('#order-sn').html(data['order']['order_sn']);
                    $('#payment_pee').val(data['order']['pay_fee']);

                    var html = '';
                    for(var i in data['payment']){
                        html += '<tr>';
                        html += '<td class="label">';
                        html += '<input type="radio" name="payment_code" onclick="order_fee(\''+data['payment'][i]['editaction']+'\');" value="'+data['payment'][i]['editaction']+'" '+(data['payment'][i]['editaction']==data['order']['pay_code'] ? "checked" : '')+' >';
                        html += '</td>';
                        html += '<td style="width: 80%;">';
                        html += '<img src="<?php echo $this->basePath(); ?>'+data['payment'][i]['payment_logo']['content']+'" style="border:1px solid #D7D7D7; margin-left:8px;">';
                        html += '&nbsp;<input type="hidden" name="payment_price_'+data['payment'][i]['editaction']+'" id="payment_price_'+data['payment'][i]['editaction']+'" value="'+data['payment'][i]['payment_fee']['content']+'">'+data['payment'][i]['payment_name']['content'];
                        if(data['payment'][i]['payment_fee']['content'] > 0) {
                            html += '&nbsp;&nbsp;[<strong><?php echo $this->translate('支付手续费'); ?>：'+data['payment'][i]['payment_fee']['content']+'</strong>]';
                        }
                        html += '</td></tr>';
                    }
                    $('#pay-list-show').html(html);
                }
            },
            'json');

        dlg = dialog({id:'pay_form',opacity:0.3,padding:'20px 10px 10px 20px',width:900,title:'<?php echo $this->translate('订单付款'); ?>',content:document.getElementById('pay_form'),lock:true});
        dlg.showModal();
    }
    function order_fee(payment_code) {
        var order_amount = Subtr(parseFloat($('#order-amount').html()), $('#payment_pee').val());
        order_amount = accAdd(order_amount, $('#payment_price_'+payment_code).val());

        $('#payment_pee').val($('#payment_price_'+payment_code).val());
        $('#order-amount').html(order_amount);
    }
</script>